package appconfig

import (
	"github.com/spf13/viper"
	"github.com/zeromicro/go-zero/core/logx"
)

type Mysql struct {
	Host     string
	Port     int64
	User     string
	Password string
	Database string
}

type Redis struct {
	Host     string
	Port     int64
	Password string
}

type Elasticsearch struct {
	Host string
	Port int64
}

type QiNiuYun struct {
	AccessKey string
	SecretKey string
	Bucket    string
	Url       string
}

type AppConfig struct {
	Mysql
	Redis
	Elasticsearch
	QiNiuYun
}

var AppCong AppConfig

func Init() {
	viper.SetConfigFile("../car_srv/appconfig/config.yaml")
	if err := viper.ReadInConfig(); err != nil {
		panic("读取配置文件失败")
	}
	if err := viper.Unmarshal(&AppCong); err != nil {
		panic("解析配置文件失败")
	}
	logx.Info("viper 连接配置文件成功")
}
